/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var fieldLabel2 = new Array('月份','本月','本年累计',
    '合格率','测点数','合格率','平均测点数',
    '合格率','测点数','合格率','平均测点数',
    '合格率','测点数','合格率','平均测点数',
    '合格率','测点数','合格率','平均测点数',
    '合格率','测点数','合格率','平均测点数',
    '合格率','测点数','合格率','平均测点数'
                
    );
var fieldLabel1 = new Array('本月',"本年累计","本月","本年累计","本月","本年累计","本月","本年累计","本月","本年累计","本月","本年累计","本月","本年累计"
    );
var fieldLabel = new Array("综合电压合格率","A类","B类",
    "C类","D类","D类城市居民端","D类直供农村居民端"
    );
var fieldName=new Array("yf","by","bnlj",
    "Abyhgl","Abycds","Anlhgl","Anlpjcds",
    "Bbyhgl","Bbycds","Bnlhgl","Bnlpjcds",
    "Cbyhgl","Cbycds","Cnlhgl","Cnlpjcds",
    "Dbyhgl","Dbycds","Dnlhgl","Dnlpjcds",
    "DCbyhgl","DCbycds","DCnlhgl","DCnlpjcds",
    "DNbyhgl","DNbycds","DNnlhgl","DNnlpjcds"
    );
var record_start = 0;
var _pageSize = 20;
var store;
var theme = '告警';
var now = new Date();
var beginDate = now.format('Y');
var endDate=now.add(Date.YEAR,-1).format('Y');


var dateFrom = {
    xtype: 'datefield',
    id: 'DateFrom',
    format: 'Y年m月',
    width: 150,
    value:now.add(Date.MONTH,-1),
    listeners: {
        select: function(c, date) {
            beginDate = date.format('Y-m');
            store.baseParams.beginDate = beginDate;
        }
    }  
}

var dateTo={
    xtype: 'datefield',
    id: 'DateTo',
    format: 'Y年m月',
    width: 150,
    value:now,
    listeners: {
        select: function(c, date) {
            beginDate = date.format('Y-m');
            store.baseParams.beginDate = beginDate;
        }
    }
}


function downloadExcel(){
    var datefrom=DateFrom.value;
    var dateto=DateTo.value;
    params={
        datefrom:datefrom,
        dateto:dateto
    };
    var encodeParams = Ext.urlEncode(params);
    open('../../servlet/ExcelFileCreate?'+encodeParams);
}

function buildWindow(){

    store=new Ext.data.JsonStore({               
        //data: [
        //       ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17']
        //]
        url:"../../servlet/report/voltagesummary",
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName,
        autoLoad: true
        
    });
    colModel= new Ext.grid.ColumnModel({
        columns: [
        new Ext.grid.RowNumberer({
            header :fieldLabel2[0],
            align: 'center', 
            width : 50,
            renderer: function (value, metadata, record, rowIndex) {
                return record_start + 1 + rowIndex+"月";
            }
        }),

        {
            header: fieldLabel2[1], 
            width: 100, 
            dataIndex: fieldName[1], 
            align: 'center'
        },

        {
            header: fieldLabel2[2], 
            width: 100, 
            dataIndex: fieldName[2], 
            align: 'center'
        },

        {
            header: fieldLabel2[3], 
            width: 100, 
            dataIndex: fieldName[3], 
            align: 'center'
        },

        {
            header: fieldLabel2[4], 
            width: 100, 
            dataIndex: fieldName[4], 
            align: 'center'
        },

        {
            header: fieldLabel2[5], 
            width: 100, 
            dataIndex: fieldName[5], 
            align: 'center'
        },

        {
            header: fieldLabel2[6], 
            width: 100, 
            dataIndex: fieldName[6], 
            align: 'center'
        },

        {
            header: fieldLabel2[7], 
            width: 100, 
            dataIndex: fieldName[7], 
            align: 'center'
        },

        {
            header: fieldLabel2[8], 
            width: 100, 
            dataIndex: fieldName[8], 
            align: 'center'
        },

        {
            header: fieldLabel2[9], 
            width: 100, 
            dataIndex: fieldName[9], 
            align: 'center'
        },

        {
            header: fieldLabel2[10], 
            width: 100, 
            dataIndex: fieldName[10], 
            align: 'center'
        },

        {
            header: fieldLabel2[11], 
            width: 100, 
            dataIndex: fieldName[11], 
            align: 'center'
        },

        {
            header: fieldLabel2[12], 
            width: 100, 
            dataIndex: fieldName[12], 
            align: 'center'
        },

        {
            header: fieldLabel2[13], 
            width: 100, 
            dataIndex: fieldName[13], 
            align: 'center'
        },

        {
            header: fieldLabel2[14], 
            width: 100, 
            dataIndex: fieldName[14], 
            align: 'center'
        },

        {
            header: fieldLabel2[15], 
            width: 100, 
            dataIndex: fieldName[15], 
            align: 'center'
        },

        {
            header: fieldLabel2[16], 
            width: 100, 
            dataIndex: fieldName[16], 
            align: 'center'
        },

        {
            header: fieldLabel2[17], 
            width: 100, 
            dataIndex: fieldName[11], 
            align: 'center'
        },

        {
            header: fieldLabel2[18], 
            width: 100, 
            dataIndex: fieldName[12], 
            align: 'center'
        },

        {
            header: fieldLabel2[19], 
            width: 100, 
            dataIndex: fieldName[13], 
            align: 'center'
        },

        {
            header: fieldLabel2[20], 
            width: 100, 
            dataIndex: fieldName[20], 
            align: 'center'
        },

        {
            header: fieldLabel2[21], 
            width: 100, 
            dataIndex: fieldName[21], 
            align: 'center'
        },

        {
            header: fieldLabel2[22], 
            width: 100, 
            dataIndex: fieldName[22], 
            align: 'center'
        },

        {
            header: fieldLabel2[23], 
            width: 100, 
            dataIndex: fieldName[23], 
            align: 'center'
        },

        {
            header: fieldLabel2[24], 
            width:100, 
            dataIndex: fieldName[24], 
            align: 'center'
        },

        {
            header: fieldLabel2[25], 
            width: 100, 
            dataIndex: fieldName[25], 
            align: 'center'
        },

        {
            header: fieldLabel2[26], 
            width: 100, 
            dataIndex: fieldName[26], 
            align: 'center'
        }  
                                                    
        ],
                                            
        defaultSortable: true,
        rows: [
        [
        {
            width: 100, 
            rowspan: 2
        },

        {
             width: 100, 
            header: fieldLabel[0], 
            colspan: 2, 
            align: 'center',
            rowspan:1
        }, 

        {
            width: 100, 
            header: fieldLabel[1], 
            colspan: 4, 
            align: 'center',
            rowspan:1
        },

        {
            width: 100, 
            header: fieldLabel[2], 
            colspan: 4, 
            align: 'center',
            rowspan:1
        },

        {
            width: 100, 
            header: fieldLabel[3], 
            colspan: 4, 
            align: 'center',
            rowspan:1
        },

        {
            width: 100, 
            header: fieldLabel[4], 
            colspan: 4, 
            align: 'center',
            rowspan:1
        },

        {
            width: 100, 
            header: fieldLabel[5], 
            colspan: 4, 
            align: 'center',
            rowspan:1
        },

        {
            width: 100, 
            header: fieldLabel[6], 
            colspan: 4, 
            align: 'center',
            rowspan:1
        },
        ], [
        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            header: fieldLabel1[0], 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: fieldLabel1[1], 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: fieldLabel1[2], 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: fieldLabel1[3], 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: fieldLabel1[4], 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: fieldLabel1[5], 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: fieldLabel1[6], 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: fieldLabel1[7], 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: fieldLabel1[8], 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: fieldLabel1[9], 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: fieldLabel1[10], 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: fieldLabel1[11], 
            colspan: 2, 
            align: 'center'
        },
        ]
        ]
    });
                                    
    var grid = new Ext.grid.GridPanel({
        title: '供电电压合格率汇总统计表',
        store: store,
        colModel:colModel,
        enableColumnMove: false,
        viewConfig: {
            forceFit: false
        },
        plugins: [new Ext.ux.plugins.GroupHeaderGrid()],
        
        loadMask: true,
        tbar: new Ext.Toolbar([
        {
            text: "选择开始日期：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        dateFrom,
        '-',
        {
            text: "选择结束日期：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        dateTo,
        '-',
        {
            xtype: 'button',
            text: '搜索',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: function() {
                store.load({
                    params: {
                        start: 0, 
                        limit: _pageSize
                    }
                });
            }
        },
        '-',
        {
            xtype: 'button',
            text: '导出',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: downloadExcel
        },
        ]),
        bbar: new Ext.PagingToolbar({
            pageSize: _pageSize,
            store: store,
            displayInfo: true,
            displayMsg: '显示记录：{0} - {1}   总记录：{2}',
            emptyMsg: "目前没有" + theme + '信息'
        })
    });
    store.load({
        params: {
            start: 0, 
            limit: _pageSize
        }
    });
    
    var applicationUI = new Ext.Viewport({
        layout: "fit",
        items: [
        grid
        ]
    });
}
Ext.onReady(buildWindow);  